// video_recorder_node.hpp

#ifndef VIDEO_RECORDER_NODE_HPP
#define VIDEO_RECORDER_NODE_HPP

#include "cv_bridge/cv_bridge.h"
#include "opencv2/opencv.hpp"
#include "rclcpp/rclcpp.hpp"
#include "sensor_msgs/msg/camera_info.hpp"
#include "sensor_msgs/msg/image.hpp"
#include <image_transport/image_transport.hpp>
#include <memory>
#include <string>
#include <chrono>

namespace video_recorder {

class VideoRecorderNode : public rclcpp::Node {
public:
  explicit VideoRecorderNode(
      const rclcpp::NodeOptions &options = rclcpp::NodeOptions());

  ~VideoRecorderNode();

private:
  // 图像订阅者
  rclcpp::Subscription<sensor_msgs::msg::Image>::SharedPtr image_sub_;
  
  // OpenCV视频写入器
  cv::VideoWriter video_writer_;
  
  // 参数
  std::string output_path_;
  std::string video_format_;
  int video_fps_;
  int video_width_;
  int video_height_;
  
  // 帧率计算
  size_t frame_count_;
  rclcpp::Time last_time_;
  
  // 是否已初始化视频写入器
  bool writer_initialized_;
  
  // 回调函数
  void imageCallback(const sensor_msgs::msg::Image::ConstSharedPtr &msg);
  
  // 初始化视频写入器
  bool initVideoWriter(int width, int height);
};

} // namespace video_recorder

#endif // VIDEO_RECORDER_NODE_HPP